package oop.ex3.nameserver;

import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import oop.ex3.Exception.WrongNumOfParamsException;
import oop.ex3.nameserver.actions.AddFile;

public class MyNameServer {
	
	//constants
	private static final int PORT_PLACE = 0;
	private static final int NUM_OF_PARAMS = 1;
	private static final int CORE_POOL_SIZE = 20;
	private static final int MAX_POOL_SIZE = 100;
	private static final long KEEP_ALIVE_TIME = 100000000;
	private static final ArrayBlockingQueue<Runnable> _queue = 
		new ArrayBlockingQueue<Runnable>(CORE_POOL_SIZE);
	
	
	//TODO these should be finals. check how you do it.
	private static int _port;	
	private static NSContext _context;
	//TODO find out which params you wanna give
	protected static ExecutorService _executor = 
		Executors.newCachedThreadPool();
	
	public static void main(String[] args) {
		try {
			if (args.length != NUM_OF_PARAMS){
				throw new WrongNumOfParamsException();
			}
			//create fields
			_port = Integer.parseInt(args[PORT_PLACE]);
			_context = new NSContext(_executor);
			
			_executor.execute(new Listener(_port, _context, _executor));
			
		}
		catch (WrongNumOfParamsException e){
			e.printStackTrace();
			System.err.println("Error");
			System.exit(-1);
			//TODO later delete it and thin what you want to do with it
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}	

}
